var $ = require("../../utils/Ajax.js");
Page({
  data: {
    Address:[],
    QQ:null
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "我的收货地址"
    }) 
    if (options.QQ != undefined || options.QQ != ''){
      this.setData({
        QQ: options.QQ
      })
    }
  },

  onShow: function () {
    var that = this;
    $.Ajax("api/address", "GET", {}, function (res) {
      console.log(res)
      if (res.s) {
        that.setData({
          Address: res.d.userAdress
        })
      } else {
        wx.showToast({
          title: res.m,
          icon: 'none',
          duration: 3000,
          mask: true
        })
      }
    })
  },

  // 添加新地址
  AddAddress: function(){
    wx.navigateTo({
      url: '../AddAddress/AddAddress',
    })
  },

  // 选择变动的收货地址
  SubmitOrderAddress: function(e){
    if (Number(this.data.QQ) == 812100002) {
      var Index = e.currentTarget.dataset.index_;
      var Address = this.data.Address;
      wx.setStorageSync('SubmitOrderAddress', Address[Index]);
      wx.navigateBack({
        delta: 1
      })
    }
  },

  // 点击编辑收货地址
  EditAddress: function(e){
    var Id = e.currentTarget.dataset.id;
    var Name = e.currentTarget.dataset.name;
    var Phone = e.currentTarget.dataset.phone;
    var Address = e.currentTarget.dataset.address;
    var IsDefault = e.currentTarget.dataset.isdefault;
    wx.navigateTo({
      url: '../EditAddress/EditAddress?Id=' + Id + "&Name=" + Name + "&Phone=" + Phone + "&Address=" + Address + "&IsDefault=" + IsDefault,
    })
  }
})